<?php

/**
 * @application Shanghai University Course Selection Assistance
 * @author deltamaster
 * @copyright Softrank Research Center
 * @version 2.2.1.0
 */

if (!defined('IN_XK'))
{
	exit('Access Denied');
}

class Error
{
	public $codeMain;
	public $codeSub;

	public function Error($codeMain = 0, $codeSub = 0)
	{
		$this->codeMain = int($codeMain);
		$this->codeSub = int($codeSub);
	}

	/**
	 * @name GetErrorMessage
	 * @author deltamaster
	 * @level KERNEL
	 * @description Get the error message suite according to the error code.
	 * @parameters void
	 * @return array : including 'errCode', 'msgMain', 'msgDetail'.
	 * @date 2010-04-25
	 * @modifier deltamaster
	 */
	public function GetErrorMessage()
	{
		$msgMain = '';
		$msgDetail = '';
		switch ($this->codeMain)
        {
       		case 1:
       			$msgMain = 'Database Error';
       			switch ($this->codeSub)
       			{
       				case 1:
       					$msgDetail = 'Connection to the database failed. The application has to terminate. Please contact the administrator for technical support.';
       					break;
   					case 2:
   						$msgDetail = 'Cannot set charset for database connection object.';
   						break;
					case 3:
						$msgDetail = 'Failed executing SQL select statement.';
						break;
					case 4:
						$msgDetail = 'Failed executing SQL insert statement.';
						break;
					case 5:
						$msgDetail = 'Failed executing SQL update statement.';
						break;
					case 6:
						$msgDetail = 'Failed executing SQL delete statement.';
						break;
					case 7:
						$msgDetail = 'Failed executing an SQL statement.';
						break;
					case 8:
						$msgDetail = 'Failed creating a new database, probably no authentication. Please contact the administrator for further information.';
						break;
					case 9:
						$msgDetail = 'Failed creating a new data table, probably no authentication. Please contact the administrator for further information.';
						break;
   					default:
   						$msgDetail = 'Unknown Error. Please contact the administrator for technical support.';
       			}
       			break;
	       		case 2:
       			$msgMain = 'Illegal Request';
       			switch ($this->codeSub)
       			{
       				case 1:
       					$msgDetail = 'Source of request cannot be identified.';
       					break;
   					case 2:
   						$msgDetail = 'Formhash doesn\'t match. Please refresh the page and try again.';
   						break;
					case 3:
						$msgDetail = 'You are not authorized to view this page. You haven\'t logged in or your user group is not authorized to this operation.';
						break;
   					default:
   						$msgDetail = 'Unknown Error. Please contact the administrator for technical support.';
       			}
       			break;
			default:
				$msgMain = 'Unknown Error';
        		$msgDetail = 'Unknown Error! Please contact the administrator for technical support.';
        }
        $errSuite = array();
        $errSuite['errCode'] = "{$this->codeMain}:{$this->codeSub}";
        $errSuite['msgMain'] = $msgMain;
        $errSuite['msgDetail'] = $msgDetail;
        return $errSuite;
	}
}

?>